<template>
  <basic-container>
    <avue-crud :option="option"
               :data="data"
               ref="crud"
               v-model="form"
               :table-loading="loading"
               :permission="permissionList"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               :before-open="beforeOpen"
               :page="page"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @current-change="currentChange"
               @size-change="sizeChange"
               @on-load="onLoad">
      <template slot-scope="{row}"
                slot="status">
        <el-switch @change="rowSwitchChange(row)"
                   v-model="row.status"
                   active-value="ENABLE"
                   inactive-value="DISABLE">
        </el-switch>
      </template>
      <template slot-scope="{row}"
                slot="customerService">
        <el-switch @change="customerServiceSwitchChange(row)"
                   v-model="row.customerService"
                   :active-value=true
                   :inactive-value=false>
        </el-switch>
      </template>
      <template slot="search">
        <el-col  :span="8" >
          <el-form-item label="用户类型" size="mini" style="margin-top: 7px;">
            <el-select v-model="type">
              <el-option key="自营用户" label="运营人员" value="1"></el-option>
              <el-option key="所有用户" label="客户" value="2"></el-option>
              <el-option key="所有用户" label="商家" value="3"></el-option>
              <el-option key="所有用户" label="所有用户" value="4"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col  :span="8" >
          <el-form-item label-width="140px" label="账户/姓名/手机号" size="mini" style="margin-top: 7px;">
			<el-input v-model="account" placeholder="请输入账户/姓名/手机号" ></el-input>
          </el-form-item>
        </el-col>
        <el-col  :span="8" >
          <el-form-item label-width="140px" label="唯一标识码" size="mini" style="margin-top: 7px;">
            <el-input v-model="userId" placeholder="请输入唯一标识码" ></el-input>
          </el-form-item>
        </el-col>
        <el-col  :span="8" >
          <el-form-item label-width="90px" label="是否为团长" size="mini" style="margin-top: 7px;">
            <el-select v-model="groupLeaderFlag">
<!--              <el-option  key="请选择" label="" value="3"></el-option>-->
              <el-option key="否" label="否" value="0"></el-option>
              <el-option key="是" label="是" value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </template>

      <template slot-scope="{row}"
                slot="menuLeft">
      </template>
      <template slot-scope="{row,type,size}"
                slot="menu">
        <el-button :type="type"
                   :size="size"
                   icon="el-icon-thumb"
                   @click="rowRoles(row)" v-has="'/mall-cloud-base/userAccount/editItem'">分配角色</el-button>
        <el-button :type="type"
                   :size="size"
                   icon="el-icon-refresh-right"
                   @click="rowReset(row)" v-has="'/mall-cloud-system/mgr/reset'">重置密码</el-button>
        <el-button :type="type"
                   :size="size"
                   icon="el-icon-edit"
                   @click="rowEdit(row)" v-has="'/mall-cloud-base/userAccount/editItem'">编辑</el-button>
      </template>
    </avue-crud>
    <el-dialog
            title="提示"
            :visible.sync="dialogVisibleImport"
            width="30%">
      <el-upload
              class="filter-item"
              name="excelFile"
              :headers="header"
              :action = userImportURL
              :on-error="uploadFalse"
              :on-success="uploadSuccess"
              :before-upload="beforeAvatarUpload"
              :limit="1"
              accept=".xlsx,.xls"
              :show-file-list="false">
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      </el-upload>
    </el-dialog>
    <el-dialog title="分配角色"
               :visible.sync="box"
               width="40%">
      <el-scrollbar style="height:400px">
        <el-tree :data="rolesTree"
                 show-checkbox
                 node-key="id"
                 default-expand-all
                 @check="rolesChange"
                 :default-checked-keys="rolesKeys"
                 :props="{label:'name',value:'id'}">
        </el-tree>
      </el-scrollbar>
      <span slot="footer">
        <el-button type="primary"
                   size="small"
                   @click="handleSetRoles">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="新增用户"
               :visible.sync="addIsShow">
      <avue-form :option="addUserOption" ref="diaformRef" v-model="userFrom">
        <template slot="menuForm">
          <el-button type="primary" @click="btnSubmit" :loading="addLoadU" >提 交</el-button>
          <el-button  @click="handleEmpty">清 空</el-button>
        </template>
      </avue-form>
    </el-dialog>
    <el-dialog title="编辑用户信息"
               width="70%"
               :visible.sync="editIsShow">
      <avue-form :option="editAddUserOption" ref="diaEditFormRef" v-model="editUserFrom">
		  <template slot-scope="scope" slot="avatar">
		  	 <el-image
		  	      style="width: 60px; height: 60px;border-radius:60px;"
		  	      :src="editUserFrom.avatar"
		  	      fit="cover"></el-image>
		  </template>
		  <template slot-scope="scope" slot="wxNickname">
		  	<el-tag color="#fff" style="border: none;color: #333333;">{{editUserFrom.wxNickname}}</el-tag>
		  </template>
        <template slot="menuForm">
          <el-button type="primary" @click="editBtnSubmit" :loading="editLoadU" >提 交</el-button>
          <!--el-button  @click="editHandleEmpty">清 空</el-button-->
        </template>
      </avue-form>
    </el-dialog>
  </basic-container>
</template>
<script>
import {
  getList,
  getUser,
  remove,
  update,
  add,
  setRoles,
  changeStatus,
  resetPassword,
  customerServiceStatus
} from "@/api/admin/mgr";
import { getRolesTree } from "@/api/admin/roles";
import { mapGetters } from "vuex";
import {testBirthday,testPassWord,testPhone
} from '@/util/util';
import {
  getToken
} from "@/util/store";
import constants from "@/const/constants";
//校验手机号
export function testPhoneAdmin(rule, value, callback) {
  if (!value) {
    callback();
  }
  setTimeout(() => {
      const re = /^1[3|4|5|7|8|9][0-9]{9}$/;
      const rsCheck = re.test(value);
      if (!rsCheck) {
        callback(new Error('请输入正确的手机号'));
      } else {
        callback();
      }
  }, 0);
}
export default {
  watch:{
    addIsShow(val){
      if(!val){
        this.$nextTick(()=>{
          this.$refs["diaformRef"].resetForm();
        })
        this.addLoadU=false
      }
    },
    editIsShow(val){
      if(!val){
        this.$nextTick(()=>{
          this.$refs["diaEditFormRef"].resetForm();
        })
        this.editLoadU=false
      }

    }

  },
  data () {
    return {
      userImportURL:'',
      dialogVisibleImport:false,
      header: {
        Authorization: getToken()
      },
      groupLeaderFlag:'',  //是否为团长
      account:'',
      userId:'',
      type:"1", //是否是自营店铺
      editLoadU:false,
      addLoadU:false,
      flag:true,
      userFrom:{},
      editUserFrom:{},
      addUserOption: {
          submitBtn:false,
          emptyBtn:false,
          searchMenuSpan:6,
        labelWidth:120,
        column: [
              {
                  label: "账号",
                  prop: "account",
                  search: true,
                  fixed: true,
                  rules: [{
                      required: true,
                      message: "请输入账号",
                      trigger: "blur"
                  }
                  ]
              },
              {
                  label: "密码",
                  prop: "password",
                  type: 'password',
                  autocomplete:"off",
                  tip:'需满足6-20位数字,字母。可以是组合(不包含特殊符号)',
                  rules: [{
                      required: true,
                      message: "请输入密码",
                      trigger: "blur"
                  },
                    {
                      validator: testPassWord,
					  trigger: "blur"
                    }
                  ]
              },
              {
                  label: "姓名",
                  prop: "name",
                  rules: [{
                      required: true,
                      message: "请输入姓名",
                      trigger: "blur"
                  }]
              },
              {
                  label: '电话',
                  prop: 'phone',
                  width: 120,
                  rules: [{
                      validator: testPhone,
                      trigger: 'blur'
                  }]
              },
              // {
              //     label: "电子邮箱",
              //     prop: "email",
              //     hide: true,
              //     overHidden: true
              // },
              {
                  label: "用户生日",
                  type: "date",
                  prop: "birthday",
                  format: "yyyy-MM-dd hh:mm:ss",
                  valueFormat: "yyyy-MM-dd hh:mm:ss",
                  hide: true,
                  // rules: [
                  // {
                  //     required: true,
                  //     message: "请输入用户生日",
                  //     trigger: "change"
                  // },
                  // {
                  //     validator: testBirthday,
                  //     trigger: "blur"
                  // },
                  // ]
              },
              {
                  label: "用户性别",
                  prop: "sex",
                  type: "radio",
                  // rules: [{
                  //     required: true,
                  //     message: "请选择性别",
                  //     trigger: "blur"
                  // }],
                  dicData: [
                      {
                          label: "男",
                          value: '1'
                      },
                      {
                          label: "女",
                          value: '0'
                      }
                  ],
                  // valueDefault: "1",
                  hide: true
              },
			  {
			  	label: '用户区域组织',
			  	prop: 'organizationId',
				value:'organizationId',
				display:true,
			  	type: 'tree',
			  	dicUrl:'/base/organization/listTree?levelM=3',
			  	props: {
			  		label: 'name',
			  		value: 'id',
			  		children: 'childrenNodes'
			  	},
			  	span: 15,
			  	rules: [
			  		{
			  			required: false,
			  			message: '请选择用户区域组织',
			  			trigger: 'change'
			  		}
			  	]
			  },
          ]
      },
      editAddUserOption: {
            submitBtn:false,
            emptyBtn:false,
            searchMenuSpan:6,
			labelWidth:120,
            column: [
                {
                    label: "微信头像",
                    prop: "avatar",
					formslot: true,
                },
                {
                    label: "微信昵称",
                    prop: "wxNickname",
					formslot: true,
                },
                {
                    label: "账号",
                    prop: "account",
                    search: true,
                    fixed: true,
                    rules: [{
                        required: true,
                        message: "请输入账号",
                        trigger: "blur"
                    }
                    ]
                },
                {
                    label: "姓名",
                    prop: "name",
                    rules: [{
                        required: true,
                        message: "请输入姓名",
                        trigger: "blur"
                    }]
                },
              {
                label: '电话',
                prop: 'phone',
                width: 120,
                display: false,
                maxlength:11,
                rules: [{
                  required:true,
                  validator: testPhone,
                  trigger: 'blur'
                }]
              },
              {
                label: '电话',
                prop: 'phone',
                width: 120,
                display: false,
                maxlength:11,
                rules: [{
                  validator: testPhoneAdmin,
                  trigger: 'blur'
                }]
              },
                // {
                //     label: "电子邮箱",
                //     prop: "email",
                //     hide: true,
                //     overHidden: true
                // },
                {
                    label: "用户生日",
                    type: "date",
                    prop: "birthday",
                    format: "yyyy-MM-dd hh:mm:ss",
                    valueFormat: "yyyy-MM-dd hh:mm:ss",
                    hide: true,
                    // rules: [
                    // {
                    //     required: true,
                    //     message: "请输入用户生日",
                    //     trigger: "change"
                    // },
                    // {
                    //     validator: testBirthday,
                    //     trigger: "blur"
                    // },
                    // ]
                },
                {
                    label: "用户性别",
                    prop: "sex",
                    type: "radio",
                    // rules: [{
                    //     required: true,
                    //     message: "请选择性别",
                    //     trigger: "blur"
                    // }],
                    dicData: [
                        {
                            label: "男",
                            value: '1'
                        },
                        {
                            label: "女",
                            value: '0'
                        }
                    ],
                    hide: true
                },
                {
                    label: "账号状态",
                    prop: "status",
                    value: "status",
                    type: 'radio',
                    dicData: [
                        {
                            label: "关闭",
                            value: 'DISABLE'
                        },
                        {
                            label: "开启",
                            value: 'ENABLE'
                        },
                    ],
                },
				{
					label: '用户区域组织',
					prop: 'organizationId',
					value:'organizationId',
					display:true,
					type: 'tree',
                    defaultExpandAll:false,
					dicUrl:'/base/organization/listTree?levelM=3',
					props: {
						label: 'name',
						value: 'id',
						children: 'childrenNodes'
					},
					span: 15,
					rules: [
						{
							required: false,
							message: '请选择用户区域组织',
							trigger: 'change'
						}
					]
				},
            ]
        },
      display: true,
      addIsShow: false,
      editIsShow: false,
      form: {},
      query: {},
      loading: true,
      rolesTree: [],
      rolesKeys: [],
      box: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option: {
        size: 'mini',
        tip: false,
        border: true,
        index: true,
        rowKey: 'userId',
        height: 'auto',
        // calcHeight: 380,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        viewBtn: false,
        dialogType: 'dialog',
        menuWidth: 240,
        searchMenuSpan:6,
        column: [
          {
            label: "账号",
            prop: "account",
            // search: true,
            fixed: true,
            rules: [{
              required: true,
              message: "请输入账号",
              trigger: "blur"
            } ]
          },
          {
            label: "密码",
            prop: "password",
            type: 'password',
            hide: true,
            rules: [{
              required: true,
              message: "请输入密码",
              trigger: "blur"
            }]
          },
          {
            label: "姓名",
            prop: "name",
            rules: [{
              required: true,
              message: "请输入姓名",
              trigger: "blur"
            }]
          },
          {
            label: "用户类型",
            prop: "userType",
            editDisplay:false
          },
          {
            label: '电话',
            prop: 'phone',
            width: 120,
            rules: [{
                validator: testPhone,
                trigger: 'blur'
            }]
          },
          // {
          //   label: "电子邮箱",
          //   prop: "email",
          //   hide: true,
          //   overHidden: true
          // },
          {
            label: "用户生日",
            type: "date",
            prop: "birthday",
            format: "yyyy-MM-dd hh:mm:ss",
            valueFormat: "yyyy-MM-dd hh:mm:ss",
            hide: true,
            // rules: [
            // {
            //   required: true,
            //   message: "请输入用户生日",
            //     trigger: "change"
            // },
            // {
            //     validator: testBirthday,
            //     trigger: "blur"
            // },
            // ]
          },
          {
            label: "用户性别",
            prop: "sex",
            type: "radio",
            // rules: [{
            //   required: true,
            //   message: "请选择性别",
            //   trigger: "blur"
            // }],
            dicData: [
              {
                label: "男",
                value: '1'
              },
              {
                label: "女",
                value: '0'
              }
            ],
            hide: true
          },
          {
            label: "账号状态",
            prop: "status",
            slot: true,
            type: 'switch',
            dicData: [
              {
                label: "关闭",
                value: 'DISABLE'
              },
              {
                label: "开启",
                value: 'ENABLE'
              },
            ],
          },
          {
            label: "是否是客服",
            prop: "customerService",
            slot: true,
            type: 'switch',
            width:80,
            dicData: [
              {
                label: "否",
                value: 0
              },
              {
                label: "是",
                value: 1
              },
            ],
          },
          {
            label: "唯一标识码",
            prop: "userId",
            width: 150,
            display: false,

          },
          {
            label: "创建时间",
            prop: "createTime",
            width: 150,
            display: false,
          },
            {
                label:"用户角色",
                prop:"roleName",
                width:100,
                display:false,
            },
          {
            label:"是否为团长",
            prop:"groupLeaderFlag",
            width:100,
            display:false,
            dicData: [
              {
                label: "否",
                value: 0
              },
              {
                label: "是",
                value: 1
              },
            ],
          }
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission", 'userInfo']),
    permissionList () {
      return {

      };
    },
  },
  methods: {
    addUser(){
      //新增用户处理弹窗
      this.$nextTick(()=>{
        this.$refs["diaformRef"].resetForm();
      })
      this.addIsShow = true;
      console.log(this.userFrom)
    },
    rowEdit(row){
      //行编辑事件
		if(row.groupLeaderFlag==0){//不是团长
			this.editAddUserOption.column[0].display=false
			this.editAddUserOption.column[1].display=false
		}else{
			this.editAddUserOption.column[0].display=true
			this.editAddUserOption.column[1].display=true
		}
      console.log('row',row)
      if(row.userType == '运营用户') {
        console.log('display==true')
        this.editAddUserOption.column[4].display=false
        this.editAddUserOption.column[5].display=true
      }else {
        console.log('display==false')
        this.editAddUserOption.column[4].display=true
        this.editAddUserOption.column[5].display=false
      }
      console.log('editAddUserOption',this.editAddUserOption)
      this.editIsShow = true;
      this.editUserFrom.account = row.account
      this.editUserFrom.avatar = row.avatar
      this.editUserFrom.wxNickname = row.wxNickname ||''
      this.editUserFrom.name = row.name
      this.editUserFrom.phone = row.phone || ''
      this.editUserFrom.birthday = row.birthday
      this.editUserFrom.sex = row.sex
      this.editUserFrom.status = row.status
      this.editUserFrom.userId = row.userId;
      this.editUserFrom.organizationId = Number(row.organizationId) || '' ;
      console.log('this.editUserFrom',this.editUserFrom)
    },
    btnSubmit() {
        console.log(this.userFrom)
        this.$refs['diaformRef'].validate((valid) => {
            if (valid) {
              this.addLoadU=true
              if(this.userFrom.birthday){
                let value = this.userFrom.birthday;
                let date = new Date(value.replace(/-/,"/"))
                //将时间转时间戳
                let birthday = date.getTime()
                let currentTimestamp = (new Date()).getTime();
                if(birthday > currentTimestamp){
                  this.addLoadU=false
                  this.$message.error("出生日期不能超过当前日期");
                  return ;
                }
              }else {
                this.userFrom.birthday = "";
              }
              add(this.userFrom).then(res => {
                    if (res.data.code == 200) {
                        this.addLoadU=false
                        this.loading = true;
                        this.$message({
                            type: "success",
                            message: "新增成功!"
                        });
                        this.onLoad(this.page);
                    } else {
                        this.$message({
                            type: "error",
                            message: res.data.message
                        });
                    }
                  this.addIsShow = false;
              });
            }
        })
    },
    handleEmpty(){
        this.$refs["diaformRef"].resetForm();
        this.addLoadU=false
    },
    editBtnSubmit() {
        this.$refs['diaEditFormRef'].validate((valid) => {
            if (valid) {
              this.editLoadU=true;
              if(this.editUserFrom.birthday){
                let value = this.editUserFrom.birthday;
                let date = new Date(value.replace(/-/,"/"))
                //将时间转时间戳
                let birthday = date.getTime()
                let currentTimestamp = (new Date()).getTime();
                if(birthday > currentTimestamp){
                  this.editLoadU=false
                  this.$message.error("出生日期不能超过当前日期");
                  return ;
                }
              }
              else {
                this.editUserFrom.birthday = "";
              }
              if (!this.editUserFrom.sex){
                this.editUserFrom.sex=""
              }
              update(this.editUserFrom).then(res => {

                    if (res.data.code == 200) {
                      this.editLoadU=false
                        this.loading = true;
                        this.$message({
                            type: "success",
                            message: "编辑成功!"
                        });
                        this.onLoad(this.page);
                    } else {
                        this.$message({
                            type: "error",
                            message: res.data.message
                        });
                    }
                this.editIsShow = false;
                });
            }
        })
    },
    editHandleEmpty(){
        this.$refs["diaEditFormRef"].resetForm();
      this.editLoadU=false
    },
    handleSetRoles () {
        console.log(this.form.userId)
        console.log(this.form.roleId)
        if(this.form.roleId){
            if( this.form.userId != 1 && this.form.roleId==1){
                this.$message({
                    type:'warning',
                    message:'不能设置超级管理员'
                })
                return
            }else{
                if(this.form.userId && this.form.roleId){
                    setRoles(this.form.userId, this.form.roleId).then(res => {
                      if (res.data.code == 200) {
                        this.flag = true;
                        this.$message.success('设置成功');
                        this.box = false;
                        this.onLoad(this.page);
                        this.form = {};
                      } else {
                        this.$message.error(res.data.message);
                      }
                    })
                }else{
                    return
                }
            }
        }
        else{
            this.$message.error("请至少给该用户分配一个权限");
        }

    },
    rolesChange (data, checked) {
      this.form.roleId = checked.checkedKeys.join(',')
    },
    rowRoles (row) {
      this.form = row;
      this.form.roleId = this.form.roleId || '';
      this.rolesKeys = row.roleId.split(',')
      this.box = true;
        this.onLoad(this.page);
    },
    rowSwitchChange (row) {
      this.$confirm('是否改变该用户状态?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (row.status === 'ENABLE') {
          changeStatus(row.userId, 'unfreeze').then(res=>{
            if(res.data.code==200) {
              this.$message({
                type: 'success',
                message: '设置成功'
              });
              this.onLoad(this.page)
            }else {
              this.$message({
                type: 'error',
                message: res.data.message
              });
            }
          });
        } else {
          changeStatus(row.userId, 'freeze').then(res=>{
            if(res.data.code==200) {
              this.$message({
                type: 'success',
                message: '设置成功'
              });
              this.onLoad(this.page)
            }else {
              this.$message({
                type: 'error',
                message: res.data.message
              });
            }
          });
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
        this.onLoad(this.page)
      });
    },
    customerServiceSwitchChange(row) {
      this.$confirm('是否改变该用户的客服状态?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        customerServiceStatus(row.userId, row.customerService).then(res=>{
          if(res.data.code==200) {
            this.$message({
              type: 'success',
              message: '设置成功'
            });
            this.onLoad(this.page)
          }else {
            this.$message({
              type: 'error',
              message: res.data.message
            });
          }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
        this.onLoad(this.page)
      });

    },

    rowSave (row, loading, done) {
      row.position = row.positionIds;
      row.deptName = row.$deptId;
      row.repassword = row.password;
      console.log(row)
      add(row).then(() => {
        loading();
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      }, error => {
        done();
        
      });
    },
    rowUpdate (row, index, loading, done) {
      row.position = row.positionIds;
      update(row).then(() => {
        loading();
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      }, error => {
        done();
        
      });
    },
    rowDel (row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return remove(row.userId);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    searchReset () {
      this.query = {};
	  this.account=''
      this.userId = ''
      this.groupLeaderFlag=''
      this.onLoad(this.page);
    },
    searchChange (params,done) {
      //每次搜索，都从第一页开始查询
      this.page.currentPage=1;
      this.query = params;
      this.onLoad(this.page, params,done);
    },
    rowReset (row) {
      this.$confirm("确定将选择账号的密码重置为111111?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return resetPassword(row.userId);
        })
        .then(() => {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    beforeOpen (done, type) {
      if (["edit", "view"].includes(type)) {
        getUser(this.form.userId).then(res => {
          this.form = res.data.data;
          this.form.positionIds = this.form.positionIds.split(',');
        });
      }
      done();
      setTimeout(() => {
        if ('add' === type) {
          this.form.status = 'ENABLE'
        }
      }, 0)

    },
    currentChange (currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange (pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange () {
      this.onLoad(this.page);
    },
    onLoad (page, params = {},done) {
      params.type=this.type;
      params.account=this.account;
      params.userId = this.userId;
	  if(this.groupLeaderFlag==3){
		  params.groupLeaderFlag= ''
	  }else{
		  params.groupLeaderFlag=this.groupLeaderFlag
	  }
      
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        if(done){
          done();
        }
        this.loading = false;
        const data = res.data;
        this.page.total = data.count;
        this.data = data.data;
        //转化字典
        this.data.forEach(ele => {
          ele.positionIds = ele.positionIds.split(',')
        })
      });
      getRolesTree(this.userInfo.id).then(res => {
          console.log(res.data)
        this.rolesTree = res.data;
      });
    },
    uploadSuccess(response, file, fileList) {
      console.log(response)
      if (response.code==200) {
        this.$message({
          message: response.message,
          type: 'success'
        });
      } else {
        this.$message({
          message: response.message,
          type: 'error'
        });
      }
    },
    uploadFalse(response, file, fileList) {
      this.$message({
        message: '文件上传失败！',
        type: 'error'
      });
    },
    // 变换要导入的url
    changeImportURL(flagUrl){
      if (flagUrl===1){
        this.userImportURL = "api/mgr/excelImportIdmUser"
      }else if (flagUrl===2){
        this.userImportURL = "api/mgr/excelImportGuiXinUser"
      }
      console.log(this.userImportURL);
    },

    // 上传前对文件的大小的判断
    beforeAvatarUpload(file) {
      const extension = file.name.split(".")[1] === "xls";
      const extension2 = file.name.split(".")[1] === "xlsx";
      const isLt2M = file.size / 1024 / 1024 < 50;
      if (!extension && !extension2) {
        this.$message({
          message: '上传模板只能是 xls、xlsx格式!',
          type: 'error'
        });
      }
      if (!isLt2M) {
        console.log("上传模板大小不能超过 50MB!");
        this.$message({
          message: '上传模板大小不能超过 50MB!',
          type: 'error'
        });
      }
      return extension || extension2 || extension3 || (extension4 && isLt2M);
    }
  }
};
var YES_OR_NO_STR = [{
  label: '是',
  value: '1'
}, {
  label: '否',
  value: '0'
}, ]
</script>

<style>
</style>
